# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/5/27 15:41
from PyQt5.Qt import *


class Window(QWidget):
	def __init__(self):
		super().__init__()
		self.setWindowTitle('QListView学习')
		self.resize(500, 500)
		self.move(400,250)
		self.data_list = [f"Itme{i}" for i in range(40)]
		print(self.data_list)
		self.setup_ui()

	def setup_ui(self):
		list_view = QListView(self) # 创建list view对象
		list_view.resize(300,300)
		slm = QStringListModel() # 创建model模型
		slm.setStringList(self.data_list)
		list_view.setModel(slm) # 为视图设置模型

		# 方向
		# list_view.setFlow(QListView.TopToBottom)
		# list_view.setFlow(QListView.LeftToRight)

		# 布局模式
		# list_view.setLayoutMode(QListView.SinglePass)
		list_view.setBatchSize(5)
		list_view.setLayoutMode(QListView.Batched)

		list_view.clicked.connect(self.click_list)
		QModelIndex

	def click_list(self,model_index):
		print(model_index)
		QMessageBox.information(self,"QListView","你选择了:"+self.data_list[model_index.row()])
		print('点击的是:'+str(model_index.row()))



if __name__ == '__main__':
	import sys

	app = QApplication(sys.argv)
	window = Window()
	window.show()
	sys.exit(app.exec_())